package com.parking.stall.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.parking.common.core.model.PageInfo;
import com.parking.common.core.model.StateData;
import com.parking.common.core.util.DateUtil;
import com.parking.stall.client.form.OrderTimeForm;
import com.parking.stall.client.form.SelectDistanceCertifiedInfoForm;
import com.parking.stall.client.dto.*;
import com.parking.stall.dao.StallCheckMapper;
import com.parking.stall.dao.StallRentTimeMapper;
import com.parking.stall.dto.*;
import com.parking.stall.entity.StallCheck;
import com.parking.stall.entity.StallInfo;
import com.parking.stall.dao.StallInfoMapper;
import com.parking.stall.entity.StallRentTime;
import com.parking.stall.exception.StallException;
import com.parking.stall.exceptionCode.StallExceptionCode;
import com.parking.stall.form.RentTimeForm;
import com.parking.stall.form.SetRentTimeForm;
import com.parking.stall.param.UserRentTimeParam;
import com.parking.stall.param.*;
import com.parking.stall.service.StallInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.parking.stall.service.StallRentTimeService;
import com.parking.stall.service.call.PageInfoCheck;
import com.parking.stall.service.call.ServeCallClass;
import com.parking.stall.service.call.StringDispose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 彭于晏
 * @since 2023年11月29日
 */
@Service
public class StallInfoServiceImpl extends ServiceImpl<StallInfoMapper, StallInfo> implements StallInfoService {
    /**
     * stallInfoMapper:车位信息mapper
     * pageInfoCheck:分页（当前页，当前页数）设置工具包
     * serveCallClass:服务调用
     * stallRentTimeService:车位时间service
     */

    @Autowired
    private StallInfoMapper stallInfoMapper;
    @Autowired
    private PageInfoCheck pageInfoCheck;
    @Autowired
    private ServeCallClass serveCallClass;
    @Autowired
    private StallRentTimeMapper stallRentTimeMapper;
    @Autowired
    private StallRentTimeService stallRentTimeService;
    @Autowired
    private StallCheckMapper stallCheckMapper;
    /**
     * platformSelect:平台查询车位信息（分页、带条件）
     * @param param 平台查询车位信息对象
     * @return PageInfo：分页对象
     * @throws Exception
     */
    @Override
    public PageInfo platformSelect(PlatformSelectStallInfoParam param) throws Exception {
        //分页判断
        Long current = pageInfoCheck.currentSet(param.getCurrent());
        Long size = pageInfoCheck.sizeSet(param.getSize());

        //创建查询对象
        QueryWrapper<StallInfo> queryWrapper = new QueryWrapper<>();

        //可变参数判断(物业信息id、车位类型、车位归属、车位上下架状态)
        if (param.getCertifiedInfoId() != null) {
            queryWrapper.eq("certified_info_id",param.getCertifiedInfoId());
        }
        if (param.getStallType() != null) {
            if ((param.getStallType() == StateData.STALL_TYPE_NORMAL)
                    ||(param.getStallType() == StateData.STALL_TYPE_CHARGE)) {
                queryWrapper.eq("stall_type",param.getStallType());
            }else throw new StallException(StallExceptionCode.STALL_TYPE_PARAM_ERROR);//车位类型参数错误
        }
        if (param.getStallInfoAffiliation()!=null) {
            if ((param.getStallInfoAffiliation()== StateData.STALL_IS_RENTERS)
                    ||(param.getStallInfoAffiliation()==StateData.STALL_IS_CERTIFIED)) {
                queryWrapper.eq("stall_info_affiliation",param.getStallInfoAffiliation());
            }else throw new StallException(StallExceptionCode.STALL_AFFILIATION_PARAM_ERROR);//车位归属参数错误
        }
        if (param.getStallUpDownState()!=null) {
            if ((param.getStallUpDownState() == StateData.STALL_STATE_DOWN)
                    ||(param.getStallUpDownState() == StateData.STALL_STATE_UP)) {
                queryWrapper.eq("stall_up_down_state",param.getStallUpDownState());
            }else throw new StallException(StallExceptionCode.STALL_UP_DOWN_PARAM_ERROR);//车位上下架参数错误
        }
        Page<StallInfo> page = stallInfoMapper.selectPage(new Page<StallInfo>(current, size), queryWrapper);
        List<StallInfo> stallInfoList = page.getRecords();
        List<PlatformSelectStallInfoDTO> dtos = BeanUtil.copyToList(stallInfoList, PlatformSelectStallInfoDTO.class);

        if (dtos!=null){
            Set<Integer> rentersInfoIds = new HashSet<>();
            Set<Integer> certifiedInfoIds = new HashSet<>();
            for (PlatformSelectStallInfoDTO dto : dtos) {
                rentersInfoIds.add(dto.getRentersInfoId());
                certifiedInfoIds.add(dto.getCertifiedInfoId());
            }
            if (certifiedInfoIds!=null){
                Set<CertifiedInfoByIdsDTO> setCertifiedInfo  = serveCallClass.selectCertifiedInfoByIds(certifiedInfoIds);
                for (PlatformSelectStallInfoDTO dto : dtos) {
                    for (CertifiedInfoByIdsDTO set : setCertifiedInfo) {
                        if (dto.getCertifiedInfoId()==set.getCertifiedInfoId()){
                            dto.setCertifiedInfoAddress(set.getCertifiedInfoAddress());
                            dto.setRentersInfoName(set.getCertifiedInfoName());
                            dto.setCertifiedInfoTel(set.getCertifiedInfoTel());
                            dto.setStallChargeNum(set.getStallChargeNum());
                            dto.setChargeUnitPrice(set.getChargeUnitPrice());
                            dto.setStallCommonNum(set.getStallCommonNum());
                            dto.setStallUnitPrice(set.getStallUnitPrice());
                        }
                    }
                }
            }
            if (rentersInfoIds!=null){
                List<StallCheck> stallCheckList = stallCheckMapper.selectList(new QueryWrapper<StallCheck>().in("renters_info_id", rentersInfoIds));
                for (PlatformSelectStallInfoDTO dto : dtos) {
                    for (StallCheck stallCheck : stallCheckList) {
                        if (dto.getStallInfoId()==stallCheck.getStallInfoId()) {
                            dto.setRentersInfoName(stallCheck.getRentersRealName());
                            dto.setRentersInfoCard(stallCheck.getRentersInfoCard());
                            dto.setStallBuyProve(stallCheck.getStallBuyProve());
                        }
                    }
                }
            }
        }

        //设置分页对象数据
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPages(page.getPages());
        pageInfo.setTotal(page.getTotal());
        pageInfo.setCurrent(current);
        pageInfo.setSize(size);
        pageInfo.setRecords(dtos);

        return pageInfo;
    }

    /**
     * userSelect: 用户查询车位（分页，带条件）
     * @param param：用户查询车位信息对象
     * @return PageInfo:分页对象
     */
    @Override
    public PageInfo userSelect(UserSelectStallInfoParam param)throws Exception {
        //分页参数判断
        Long current = pageInfoCheck.currentSet(param.getCurrent());
        Long size = pageInfoCheck.sizeSet(param.getSize());

        //创建查询对象
        QueryWrapper<StallInfo> queryWrapper = new QueryWrapper<>();

        Set<DistanceCertifiedInfoDto> certifiedInfoDtoSet = null;

        //时间参数判断（可选）
        if (StringUtils.hasLength(param.getStartTime())
                && StringUtils.hasLength(param.getEndTime())){
            if (DateUtil.stringToLocalDateTime(param.getStartTime()).compareTo(DateUtil.stringToLocalDateTime(param.getEndTime())) > 0) {
                throw new StallException(StallExceptionCode.START_GT_END_TIME);//开始时间大于结束时间
            } else if (DateUtil.stringToLocalDateTime(param.getStartTime()).compareTo(DateUtil.stringToLocalDateTime(param.getEndTime())) == 0) {
                throw new StallException(StallExceptionCode.START_EQ_END_TIME);//开始时间等于结束时间
            }
            //时间参数判断
            String endTimeParam = param.getEndTime();
            String startTimeParam = param.getStartTime();
            if (DateUtil.stringToLocalDateTime(startTimeParam).compareTo(LocalDateTime.now())<0){
                throw new StallException(StallExceptionCode.NOW_GT_START_DATE);//开始日期小于当前日期
            }
            Date date = new Date();
            long date1 = date.getTime();
            long date2= date.getTime()+(1000*60*60*24);
            long date3 = date.getTime()+(1000*60*60*48);
            Long startLong = DateUtil.stringToLong1(startTimeParam);
            Long endLong = DateUtil.stringToLong1(endTimeParam);
            if (!(startLong<date2 && startLong>date1)) {
                throw new StallException(StallExceptionCode.START_TIME_SURPASS_1);//开始时间不得超过1天
            }
            if (!(endLong<date3 && endLong>date1)) {
                throw new StallException(StallExceptionCode.END_TIME_SURPASS_2);//结束时间不得超过2天
            }
        }else if((!StringUtils.hasLength(param.getStartTime()) && StringUtils.hasLength(param.getEndTime()))
                ||(StringUtils.hasLength(param.getStartTime()) && !StringUtils.hasLength(param.getEndTime()))){
            throw new StallException(StallExceptionCode.USER_RENT_DATE_PARAM_ERROR);//请完善租用日期信息
        }

        //必选参数判断(物业id，定位参数（经纬度、距离）)
        if (param.getCertifiedInfoId()==null||param.getCertifiedInfoId()==0){
            throw new StallException(StallExceptionCode.CERTIFIED_INFO_ID_IS_NULL);//物业信息id不为空
        }
        if (param.getDistanceRange()==null
                || param.getDistanceRange()==0
                || param.getCertifiedInfoLatitude()==null
                || param.getCertifiedInfoLatitude()==0
                || param.getCertifiedInfoLongitude()==null
                || param.getCertifiedInfoLongitude()==0
        ) {
            throw new StallException(StallExceptionCode.LOCATION_PARAM_NO_COMPLETE);//定位信息未完善

        }else {

            SelectDistanceCertifiedInfoForm form = BeanUtil.toBean(param, SelectDistanceCertifiedInfoForm.class);
            certifiedInfoDtoSet = serveCallClass.distanceCertifiedCall(form);
            if (certifiedInfoDtoSet.size()<=0||certifiedInfoDtoSet==null) {
                PageInfo pageInfo = new PageInfo();
                pageInfo.setPages(0L);
                pageInfo.setSize(size);
                pageInfo.setTotal(0L);
                pageInfo.setCurrent(current);
                return pageInfo;
            }
            Set<Integer> ids =certifiedInfoDtoSet.stream()
                    .map(DistanceCertifiedInfoDto::getCertifiedInfoId)  // 假设getCertifiedInfoId是获取id字段的方法
                    .collect(Collectors.toSet());
            queryWrapper.in("certified_info_id",ids);
        }

        //可选参数、时间段、车位类型
        if (StringUtils.hasLength(param.getStartTime()) && StringUtils.hasLength(param.getEndTime())) {

//-----------------------------------时间段判断---------------------------------
            //时间段内已生成的订单的时间  物业（全天上架） 出租客（全天上架，时间内，日期-时间内） 取反
            Set<Integer> stallInfoIdCount = new HashSet<>();
            OrderTimeForm form = new OrderTimeForm();
            form.setEndTime(DateUtil.stringToLocalDateTime(param.getEndTime()));
            form.setStartTime(DateUtil.stringToLocalDateTime(param.getStartTime()));
            Set<Integer> stallInfoIds = serveCallClass.orderStallCall(form);
            if (stallInfoIds.size() != 0 || stallInfoIds != null) {
                for (Integer stallInfoId : stallInfoIds) {
                    stallInfoIdCount.add(stallInfoId);
                }
            }
            //出租客下架状态ids集合
            List<Integer> rentersStallInfosDown = new ArrayList<>();

            List<StallInfo> stallInfoList = stallInfoMapper.selectList(
                    new QueryWrapper<StallInfo>()
                            .eq("stall_up_down_state", StateData.STALL_STATE_DOWN));
            if (stallInfoList.size() > 0 || stallInfoList != null) {
                for (StallInfo stallInfo : stallInfoList) {
                    stallInfoIdCount.add(stallInfo.getStallInfoId());
                    if (stallInfo.getStallInfoAffiliation() == StateData.STALL_IS_RENTERS) {
                        rentersStallInfosDown.add(stallInfo.getStallInfoId());
                    }
                }
            }

            QueryWrapper<StallRentTime> timeQueryWrapper = new QueryWrapper<>();
            timeQueryWrapper.isNotNull("rent_time");
            if (rentersStallInfosDown.size() > 0 || rentersStallInfosDown != null) {
                timeQueryWrapper.ne("stall_rent_time_id", rentersStallInfosDown);
            }
            //上架，出租时间不为空（年月日时分秒，时分秒）
            List<StallRentTime> stallRentTimes = stallRentTimeMapper.selectList(timeQueryWrapper);

            String starDate = param.getStartTime().substring(0, 10);
            String endDate = param.getEndTime().substring(0, 10);

            //开始时间
            LocalDateTime localDateStartTime = DateUtil.stringToLocalDateTime(param.getStartTime());
            int startHour = localDateStartTime.getHour();
            int startSecond = localDateStartTime.getSecond();
            //结束时间
            LocalDateTime localDateEndTime = DateUtil.stringToLocalDateTime(param.getEndTime());
            int endHour = localDateEndTime.getHour();
            int endSecond = localDateEndTime.getSecond();
            if (stallRentTimes != null) {
                for (StallRentTime stallRentTime : stallRentTimes) {   //时间不为空的集合
                    if (starDate.equals("") && endDate.equals("")) {  //日期段为空
                        //—————————————————————————重复代码1开始———————————————————————————————————————————
                        //json转list
                        String rentTime = stallRentTime.getRentTime();
                        JSONArray jsonArray = JSONUtil.parseArray(rentTime);
                        List<JSONObject> jsonObjectList = jsonArray.toList(JSONObject.class);
                        ArrayList<RentTimeForm> rentTimeForms = new ArrayList<>();

                        for (JSONObject jsonObject : jsonObjectList) {
                            int startTime = jsonObject.getInt("startTime");
                            int endTime = jsonObject.getInt("endTime");
                            RentTimeForm timeRange = new RentTimeForm(startTime, endTime);
                            rentTimeForms.add(timeRange);
                        }

                        //list集合的字符串
                        String src = "";
                        for (RentTimeForm rent : rentTimeForms) {
                            if (rent!=null){
                                if (src.equals("")) src = rent.getStartTime() + "," + rent.getEndTime();
                                else src = src + "," + rent.getStartTime() + "," + rent.getEndTime();
                            }
                        }
                        //获取重复下标
                        List<Integer> indexList = StringDispose.getRepetitionIndex(src);
                        //字符串排序
                        String numStringSort = StringDispose.numStringSort(src);
                        //获取没有重复下标的字符串
                        String numStringDeduplication = StringDispose.getNumStringDeduplication(numStringSort, indexList);
                        //转string的list集合
                        List<String> numberList = Arrays.asList(numStringDeduplication.split(","));
                        //转对象的list集合
                        List<UserRentTimeParam> rentTimeFormList = new ArrayList<>();
                        for (int i = 0; i < numberList.size(); i++) {
                            UserRentTimeParam userRentTimeForm=new UserRentTimeParam();
                            if (2 * i + 1 < numberList.size()) {
                                String s1 = numberList.get(2 * i);
                                String s2 = numberList.get(2 * i + 1);
                                userRentTimeForm.setStartTime(Integer.parseInt(s1));
                                userRentTimeForm.setEndTime(Integer.parseInt(s2));
                                rentTimeFormList.add(userRentTimeForm);
                            }
                        }

                        int num = 0;
                        //时间比较
                        for (UserRentTimeParam userRentTimeForm : rentTimeFormList) {
                            Integer endTimeDB = userRentTimeForm.getEndTime();
                            Integer startTimeDB = userRentTimeForm.getStartTime();
                            //                        1-2； 1：30-2：30
                            if (endSecond != 0) {
                                endHour = endHour + 1;
                            }
                            if (startTimeDB < startHour && endHour < endTimeDB) {
                                num = num + 1;
                            }
                        }
                        if (num == 0) {
                            stallInfoIdCount.add(stallRentTime.getStallInfoId());
                        }
                        //—————————————————————————重复代码1结束———————————————————————————————————————————
                    } else if ((!starDate.equals("") && endDate.equals(""))//日期段错误
                            || (starDate.equals("") && !endDate.equals(""))) {
                        throw new StallException(StallExceptionCode.STALL_RENT_DATE_ERROR);//出租时间有错
                    } else {
                        //日期段不为空
                        if (starDate.equals(stallRentTime.getRentStartDate())
                                && endDate.equals(stallRentTime.getRentEndDate())) {
                            //—————————————————————————重复代码1开始———————————————————————————————————————————
                            //json转list
                            String rentTime = stallRentTime.getRentTime();
                            JSONArray jsonArray = JSONUtil.parseArray(rentTime);
                            List<JSONObject> jsonObjectList = jsonArray.toList(JSONObject.class);
                            ArrayList<RentTimeForm> rentTimeForms = new ArrayList<>();

                            for (JSONObject jsonObject : jsonObjectList) {
                                int startTime = jsonObject.getInt("startTime");
                                int endTime = jsonObject.getInt("endTime");
                                RentTimeForm timeRange = new RentTimeForm(startTime, endTime);
                                rentTimeForms.add(timeRange);
                            }

                            //list集合的字符串
                            String src = "";
                            for (RentTimeForm rent : rentTimeForms) {
                                if (rent!=null){
                                    if (src.equals("")) src = rent.getStartTime() + "," + rent.getEndTime();
                                    else src = src + "," + rent.getStartTime() + "," + rent.getEndTime();
                                }
                            }
                            //获取重复下标
                            List<Integer> indexList = StringDispose.getRepetitionIndex(src);
                            //字符串排序
                            String numStringSort = StringDispose.numStringSort(src);
                            //获取没有重复下标的字符串
                            String numStringDeduplication = StringDispose.getNumStringDeduplication(numStringSort, indexList);
                            //转string的list集合
                            List<String> numberList = Arrays.asList(numStringDeduplication.split(","));
                            //转对象的list集合
                            List<UserRentTimeParam> rentTimeFormList = new ArrayList<>();
                            for (int i = 0; i < numberList.size(); i++) {
                                UserRentTimeParam userRentTimeForm=new UserRentTimeParam();
                                if (2 * i + 1 < numberList.size()) {
                                    String s1 = numberList.get(2 * i);
                                    String s2 = numberList.get(2 * i + 1);
                                    userRentTimeForm.setStartTime(Integer.parseInt(s1));
                                    userRentTimeForm.setEndTime(Integer.parseInt(s2));
                                    rentTimeFormList.add(userRentTimeForm);
                                }
                            }

                            int num = 0;
                            //时间比较
                            for (UserRentTimeParam userRentTimeForm : rentTimeFormList) {
                                Integer endTimeDB = userRentTimeForm.getEndTime();
                                Integer startTimeDB = userRentTimeForm.getStartTime();
//                               1-2； 1：30-2：30
                                if (endSecond != 0) {
                                    endHour = endHour + 1;
                                }
                                if (startTimeDB < startHour && endHour < endTimeDB) {
                                    num = num + 1;
                                }
                            }
                            if (num == 0) {
                                stallInfoIdCount.add(stallRentTime.getStallInfoId());
                            }
                            //—————————————————————————重复代码1结束———————————————————————————————————————————
                        } else stallInfoIdCount.add(stallRentTime.getStallInfoId());
                    }

                }
                queryWrapper.ne("stall_info_id", stallInfoIdCount);
            }
        }

        if (param.getCertifiedInfoId()!=null) {
            if (param.getCertifiedInfoId()<=0) {
                throw new StallException(StallExceptionCode.CERTIFIED_INFO_ID_IS_NULL);//物业信息id参数错误
            }
            queryWrapper.eq("certified_info_id",param.getCertifiedInfoId());
        }

        if (param.getStallType()!=null) {
            if ((param.getStallType()== StateData.STALL_TYPE_CHARGE)
                    ||(param.getStallType()==StateData.STALL_TYPE_NORMAL)) {
                queryWrapper.eq("stall_type",param.getStallType());
            }else throw new StallException(StallExceptionCode.STALL_TYPE_PARAM_ERROR);//车位类型参数错误
        }

        //获取：分页对象中的集合
        Page<StallInfo> stallInfoPage = stallInfoMapper.selectPage(new Page<StallInfo>(current, size), queryWrapper);
        List<StallInfo> records = stallInfoPage.getRecords();
        List<UserSelectStallInfoDto> dtos = BeanUtil.copyToList(records, UserSelectStallInfoDto.class);

        for (DistanceCertifiedInfoDto dto : certifiedInfoDtoSet) {
            for (UserSelectStallInfoDto infoDto : dtos) {
                if (infoDto.getCertifiedInfoId()==dto.getCertifiedInfoId()) {
                    infoDto.setCertifiedInfoName(dto.getCertifiedInfoName());
                    infoDto.setCertifiedInfoAddress(dto.getCertifiedInfoAddress());
                    infoDto.setCertifiedInfoScore(dto.getCertifiedInfoScore());
                    if (infoDto.getStallType()==StateData.STALL_TYPE_NORMAL){
                        infoDto.setStallUnitPrice(dto.getStallUnitPrice());
                    }else {
                        infoDto.setChargeUnitPrice(dto.getChargeUnitPrice());
                    }
                }
            }
        }

        //分页设置
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPages(stallInfoPage.getPages());
        pageInfo.setTotal(stallInfoPage.getTotal());
        pageInfo.setCurrent(stallInfoPage.getCurrent());
        pageInfo.setSize(stallInfoPage.getSize());
        pageInfo.setRecords(dtos);

        return pageInfo;
    }

    /**
     * certifiedSelect:物业查询车位（分页、带条件）
     * @param param :物业查车位信息参数
     * @return PageInfo：分页对象
     * @throws Exception
     */
    @Override
    public PageInfo certifiedSelect(CertifiedSelectStallInfoParam param)throws Exception {
        //分页参数判断
        Long current = pageInfoCheck.currentSet(param.getCurrent());
        Long size = pageInfoCheck.sizeSet(param.getSize());

        //获取：物业信息对象
        SelectCertifiedInfoDTO selectCertifiedInfoDTO = serveCallClass.certifiedServerCall(param.getCertifiedAccountId());
        if (selectCertifiedInfoDTO==null) {
            throw new StallException(StallExceptionCode.CERTIFIED_INFO_NOT_EXISTS);//物业信息对象不存在
        }
        Integer certifiedInfoId = selectCertifiedInfoDTO.getCertifiedInfoId();

        String certifiedInfoName = selectCertifiedInfoDTO.getCertifiedInfoName();

        //创建查询对象
        QueryWrapper<StallInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("certified_info_id",certifiedInfoId);

        //判断可选参数参数
        if (param.getStallType()!=null) {
            if (param.getStallType()== StateData.STALL_TYPE_NORMAL
                    ||param.getStallType()==StateData.STALL_TYPE_CHARGE) {
                queryWrapper.eq("stall_type",param.getStallType());
            }else  throw new StallException(StallExceptionCode.STALL_TYPE_PARAM_ERROR);//车位类型参数错误
        }
        if (param.getStallInfoAffiliation()!=null){
            if (param.getStallInfoAffiliation()== StateData.STALL_IS_RENTERS
                    ||param.getStallInfoAffiliation()==StateData.STALL_IS_CERTIFIED) {
                queryWrapper.eq("stall_info_affiliation",param.getStallInfoAffiliation());
            }else throw new StallException(StallExceptionCode.STALL_AFFILIATION_PARAM_ERROR);//车位归属参数错误
        }
        if (param.getStallUpDownState()!=null) {
            if (param.getStallUpDownState()== StateData.STALL_STATE_UP
                    ||param.getStallUpDownState()==StateData.STALL_STATE_DOWN) {
                queryWrapper.eq("stall_up_down_state",param.getStallUpDownState());
            }else throw new StallException(StallExceptionCode.STALL_STATE_PARAM_ERROR);//车位状态参数错误
        }
        Page<StallInfo> stallInfoPage = stallInfoMapper.selectPage(new Page<StallInfo>(current, size), queryWrapper);
        List<StallInfo> stallInfoList = stallInfoPage.getRecords();
        List<CertifiedSelectStallInfoDTO> dtos = BeanUtil.copyToList(stallInfoList, CertifiedSelectStallInfoDTO.class);

        //分页设置
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPages(stallInfoPage.getPages());
        pageInfo.setTotal(stallInfoPage.getTotal());
        pageInfo.setCurrent(stallInfoPage.getCurrent());
        pageInfo.setSize(stallInfoPage.getSize());
        pageInfo.setRecords(dtos);

        return pageInfo;
    }

    /**
     * addStall:物业新增车位（批量，带条件）
     * @param param:批量新增车位信息
     * @return true/false
     * @throws Exception
     */
    @Transactional//普通事务注解
    @Override
    public Boolean addStall(AddStallInfoParam param) throws Exception {
        //参数判断
        if (param.getStallType()==null
                || !StringUtils.hasLength(param.getStallInfoArea())
                || param.getStartStallInfoNum()==null
                || param.getStallInfoCount()==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_PARAM_NOT_FULL);//车位信息参数未完善
        }

        //判断数据库车位是否有重复
        Integer stallInfoCount = param.getStallInfoCount();
        ArrayList<Integer> integers = new ArrayList<>();
        for (Integer i = 0; i < stallInfoCount; i++) {
            integers.add(param.getStartStallInfoNum()+i);
        }
        List<StallInfo> list = list(new QueryWrapper<StallInfo>()
                .eq("stall_info_area", param.getStallInfoArea())
                .in("stall_info_num", integers));
        if (list!=null) {
            for (StallInfo stallInfo : list) {
                throw new StallException(stallInfo.getStallInfoArea()+stallInfo.getStallInfoNum()+"车位已存在，无法新增",5037);
            }
        }
        //获取：账号对象(对象、状态的判断)
        SelectCertifiedInfoDTO selectCertifiedInfoDTO = serveCallClass.certifiedServerCall(param.getCertifiedAccountId());
        if (selectCertifiedInfoDTO==null) {
            throw new StallException(StallExceptionCode.CERTIFIED_ACCOUNT_NOT_EXISTS);//物业账号对象不存在
        }
        Integer certifiedInfoId = selectCertifiedInfoDTO.getCertifiedInfoId();
        //创建查询对象
        QueryWrapper<StallInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("certified_info_id",certifiedInfoId);

        if (param.getStallInfoCount()==1) {
            StallInfo stallInfo = new StallInfo();
            StallInfo stallInfoOne = stallInfoMapper.selectOne(
                    queryWrapper.eq("stall_info_area", param.getStallInfoArea())
                            .eq("stall_info_num", param.getStartStallInfoNum()));
            if (stallInfoOne==null) {
                stallInfo.setStallType(param.getStallType());
                stallInfo.setStallUpDownState(StateData.STALL_STATE_DOWN);
                stallInfo.setCertifiedInfoId(certifiedInfoId);
                stallInfo.setStallInfoAffiliation(StateData.STALL_IS_CERTIFIED);
                stallInfo.setStallInfoNum(param.getStartStallInfoNum());
                stallInfo.setStallInfoArea(param.getStallInfoArea());
                stallInfoMapper.insert(stallInfo);
                StallRentTime stallRentTime = new StallRentTime();
                stallRentTime.setStallInfoId(stallInfo.getStallInfoId());
                stallRentTime.setStallInfoNum(param.getStartStallInfoNum());
                stallRentTime.setStallInfoArea(param.getStallInfoArea());
                stallRentTime.setStallOwnerType(StateData.STALL_IS_CERTIFIED);
                stallRentTime.setStallOwner("物业");
                stallRentTimeService.save(stallRentTime);
            }else throw new StallException(StallExceptionCode.STALL_INFO_IS_EXISTS);//车位已存在
        }else {
            queryWrapper.eq("stall_info_area", param.getStallInfoArea());
            List<StallInfo> stallInfosDB = list(queryWrapper);
            List<StallInfo> saveStallInfoDBs=new ArrayList<>();
            for (Integer i = 0; i < param.getStallInfoCount(); i++) {
                if (stallInfosDB!=null||stallInfosDB.size()>0){
                    for (StallInfo stall : stallInfosDB) {
                        if (stall.getStallInfoNum()==(param.getStartStallInfoNum()+i)) {
                            throw new StallException(param.getStallInfoArea()+(param.getStartStallInfoNum()+i)+"车位已存在",5038);//车位已存在
                        }
                    }
                }
                StallInfo stallInfo = new StallInfo();
                stallInfo.setStallType(param.getStallType());
                stallInfo.setStallUpDownState(StateData.STALL_STATE_DOWN);
                stallInfo.setCertifiedInfoId(certifiedInfoId);
                stallInfo.setStallInfoAffiliation(StateData.STALL_IS_CERTIFIED);
                stallInfo.setStallInfoNum((param.getStartStallInfoNum()+i));
                stallInfo.setStallInfoArea(param.getStallInfoArea());
                saveStallInfoDBs.add(stallInfo);
            }
            saveBatch(saveStallInfoDBs);
            List<StallInfo> stallInfoList = stallInfoMapper.selectList(
                    queryWrapper.between("stall_info_num"
                            , param.getStartStallInfoNum()
                            , param.getStartStallInfoNum() + param.getStallInfoCount()));
            List<StallRentTime> saveStallRentTimeDBs = new ArrayList<>();
            for (StallInfo stallInfo : stallInfoList) {
                StallRentTime stallRentTime = new StallRentTime();
                stallRentTime.setStallInfoId(stallInfo.getStallInfoId());
                stallRentTime.setStallInfoNum(stallInfo.getStallInfoNum());
                stallRentTime.setStallInfoArea(stallInfo.getStallInfoArea());
                stallRentTime.setStallOwnerType(StateData.STALL_IS_CERTIFIED);
                stallRentTime.setStallOwner("物业");
                saveStallRentTimeDBs.add(stallRentTime);
            }
            stallRentTimeService.saveBatch(saveStallRentTimeDBs);
        }
        return true;
    }

    /**
     * certifiedSetStallState:物业设置车位状态：上下架
     * @param param :物业设置车位上下架参数对象
     * @return Boolean
     * @throws Exception
     */
    @Transactional//普通事务注解
    @Override
    public Boolean certifiedSetStallState(CertifiedSetStallStateParam param) throws Exception{
        //参数判断
        if (param.getStallInfoIds().size()<=0
                ||param.getStallInfoIds()==null
                ||param.getStallUpDownState()==null) {
            throw new StallException(StallExceptionCode.STALL_UP_DOWN_NO_FULL);//请完善车位上下架信息参数
        }
        List<StallInfo> stallInfoList = list(new QueryWrapper<StallInfo>()
                .in("stall_info_id", param.getStallInfoIds()));
        List<Integer> stallInfoIds = param.getStallInfoIds();
        //异常车位id
        ArrayList<Integer> integers = new ArrayList<>();
        if (stallInfoList.size()!=stallInfoIds.size()) {
            for (Integer stallInfoId : stallInfoIds) {
                for (StallInfo stallInfo : stallInfoList) {
                    if (stallInfo.getStallInfoId()!=stallInfoId) {
                        integers.add(stallInfoId);
                    }
                }
            }
            throw new StallException("车位id不存在的有"+integers,5044);
        }else {
            for (StallInfo stallInfo : stallInfoList) {
                if (stallInfo.getStallInfoAffiliation()== StateData.STALL_IS_RENTERS) {
                    throw new StallException(stallInfo.getStallInfoArea()
                            +stallInfo.getStallInfoNum()
                            +"车位非物业车位",5044);
                }
            }
        }

        UpdateWrapper<StallInfo> updateWrapper = new UpdateWrapper<>();
        if (param.getStallUpDownState()== StateData.STALL_STATE_UP) {
            for (StallInfo stallInfo : stallInfoList) {
                if (stallInfo.getStallUpDownState()== StateData.STALL_STATE_UP) {
                    throw new StallException(stallInfo.getStallInfoArea()+stallInfo.getStallInfoNum()+"车位已上架",5045);//车位已上架
                }else if(stallInfo.getStallUpDownState()!= StateData.STALL_STATE_DOWN){
                    throw new StallException(StallExceptionCode.STALL_UP_DOWN_PARAM_ERROR);//车位上下架参数错误
                }
                updateWrapper.in("stall_info_id",param.getStallInfoIds())
                        .set("stall_up_down_state",param.getStallUpDownState());
            }
        }else if (param.getStallUpDownState()== StateData.STALL_STATE_DOWN){
            for (StallInfo stallInfo : stallInfoList) {
                if (stallInfo.getStallUpDownState()== StateData.STALL_STATE_UP) {
                    updateWrapper.in("stall_info_id",param.getStallInfoIds())
                            .set("stall_up_down_state",param.getStallUpDownState());
                }else if(stallInfo.getStallUpDownState()== StateData.STALL_STATE_DOWN){
                    throw new StallException(stallInfo.getStallInfoArea()+stallInfo.getStallInfoNum()+"车位已下架",5046);//车位已下架
                }else throw new StallException(StallExceptionCode.STALL_UP_DOWN_PARAM_ERROR);//车位上下架参数错误
            }
        }else {
            throw new StallException(StallExceptionCode.STALL_UP_DOWN_PARAM_ERROR);//车位上下架参数错误
        }
        stallInfoMapper.update(null,updateWrapper);
        return true;
    }

    /**
     * rentersSelect：出租客查询车位
     * @param param 出租客分页查询参数
     * @return RentersSelectStallDTO 出租客查询车位(可能多个)信息返回参数
     * @throws Exception
     */
    @Override
    public PageInfo rentersSelect (RentersSelectStallParam param) throws Exception {
        //分页参数判断
        Long current = pageInfoCheck.currentSet(param.getCurrent());
        Long size = pageInfoCheck.sizeSet(param.getSize());

        //出租客信息调用
        SelectRentersInfoDTO selectRentersInfoDTO = serveCallClass.rentersInfoCall(param.getRentersId());
        if (selectRentersInfoDTO==null) {
            throw new StallException(StallExceptionCode.RENTERS_INFO_NO_EXISTS);
        }

        //物业信息调用
        StallInfo stallInfo = list(new QueryWrapper<StallInfo>().eq("renters_info_id", selectRentersInfoDTO.getRentersInfoId())).get(1);
        if (stallInfo==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_OBJECT_IS_NULL);//车位对象不存在
        }
        SelectCertifiedInfoAndStateDTO certifiedInfoAndStateDTO = serveCallClass.certifiedInfoServerCall(stallInfo.getCertifiedInfoId());
        if (certifiedInfoAndStateDTO==null) {
            throw new StallException(StallExceptionCode.CERTIFIED_INFO_NOT_EXISTS);//物业信息对现象不存在
        }
        //创建查询对象
        QueryWrapper<StallInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("renters_info_id",selectRentersInfoDTO.getRentersInfoId());

        Page<StallInfo> stallInfoPage = stallInfoMapper.selectPage(new Page<StallInfo>(current, size), queryWrapper);
        List<StallInfo> stallInfoList = stallInfoPage.getRecords();

        List<RentersSelectStallDTO> dtos = BeanUtil.copyToList(stallInfoList, RentersSelectStallDTO.class);
        for (RentersSelectStallDTO dto : dtos) {
            dto.setCertifiedAccountState(certifiedInfoAndStateDTO.getCertifiedAccountState());
            dto.setCertifiedInfoAddress(certifiedInfoAndStateDTO.getCertifiedInfoAddress());
            dto.setCertifiedInfoName(certifiedInfoAndStateDTO.getCertifiedInfoName());
            dto.setCertifiedInfoTel(certifiedInfoAndStateDTO.getCertifiedInfoTel());
        }

        PageInfo pageInfo = new PageInfo();
        pageInfo.setPages(stallInfoPage.getPages());
        pageInfo.setTotal(stallInfoPage.getTotal());
        pageInfo.setRecords(dtos);
        pageInfo.setCurrent(stallInfoPage.getCurrent());
        pageInfo.setSize(stallInfoPage.getSize());

        return pageInfo;
    }

    /**
     * rentersSetUp:出租客设置车位上架（日期，时间批量）
     * @param param :出租客设置车位上架参数
     * @return Boolean
     * @throws Exception
     */
    @Override
    @Transactional
    public Boolean rentersSetUp(RentersSetUpStallParam param) throws Exception {
        //参数判断
        if (param.getStallInfoId()==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_PARAM_NOT_FULL);//车位信息参数未完善
        }

        StallInfo stallInfo = getById(param.getStallInfoId());
        if (stallInfo==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_OBJECT_IS_NULL);//车位对象不存在
        }
        if (stallInfo.getStallUpDownState()==StateData.STALL_STATE_UP) {
            throw new StallException(StallExceptionCode.STALL_ALREADY_IS_UP);//车已上架，无法修改
        }
        UpdateWrapper<StallRentTime> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("stall_info_id",param.getStallInfoId());

        //可选参数判断（日期-时间，时间）
        if (StringUtils.hasLength(param.getRentEndDate())
                && StringUtils.hasLength(param.getRentStartDate())) {
            if (DateUtil.stringToLocalDate(param.getRentEndDate())
                    .compareTo(DateUtil.stringToLocalDate(param.getRentStartDate()))==0) {
                throw new StallException(StallExceptionCode.START_EQ_END_DATE);//开始日期等于结束日期
            }else if(DateUtil.stringToLocalDate(param.getRentEndDate())
                    .compareTo(DateUtil.stringToLocalDate(param.getRentStartDate()))<0){
                throw new StallException(StallExceptionCode.START_GT_END_DATE);//开始日期大于结束日期
            }else if(DateUtil.stringToLocalDate(param.getRentStartDate())
                    .compareTo(LocalDate.now())<0){
                throw new StallException(StallExceptionCode.NOW_GT_START_DATE);//开始日期小于当前日期
            }else if(DateUtil.stringToLocalDate(param.getRentStartDate())
                    .compareTo(LocalDate.now())<0){
                throw new StallException(StallExceptionCode.NOW_GT_START_DATE);//开始日期小于当前日期
            }
            Long endLong = DateUtil.stringToLong(param.getRentEndDate());
            Long startLong = DateUtil.stringToLong(param.getRentStartDate());
            int dayNum=(int)((endLong-startLong)/1000/60/60/24);
            if (dayNum>30) {
                throw new StallException(StallExceptionCode.RENT_DATE_LE_30);//短租日期最多不得超过30天
            }
            if (param.getRentTimes().size()!=0||param.getRentTimes()!=null){
//-----------------------------------时间段判断---------------------------------
                List<SetRentTimeForm> setRentTimeForms = param.getRentTimes();
                for (SetRentTimeForm setRentTimeForm : setRentTimeForms) {
                    if (!( 0 <= setRentTimeForm.getStartTime() && setRentTimeForm.getStartTime()<=23) ) {
                        throw new StallException(StallExceptionCode.START_TIME_0_23);//开始时间时间范围：0-23
                    }
                    if (!( 1 <= setRentTimeForm.getEndTime()  && setRentTimeForm.getEndTime()<=24)) {
                        throw new StallException(StallExceptionCode.END_TIME_1_24);//结束时间时间范围：1-24
                    }
                }
                for (int i = 0; i < setRentTimeForms.size(); i++) {
                    for (int j = 0; j < setRentTimeForms.size(); j++) {
                        if (i!=j){
                            SetRentTimeForm rentTimeForm1 = setRentTimeForms.get(i);
                            SetRentTimeForm rentTimeForm2 = setRentTimeForms.get(j);
                            if(!((rentTimeForm1.getStartTime()<rentTimeForm2.getStartTime()
                                    &&rentTimeForm1.getEndTime()<=rentTimeForm2.getStartTime())
                                    ||
                                    (rentTimeForm1.getStartTime()>=rentTimeForm2.getEndTime()
                                            &&rentTimeForm1.getEndTime()>rentTimeForm2.getEndTime())
                                )
                              ) {
                                throw new StallException(StallExceptionCode.RENT_TIME_OVERLAP_OR_CONTAIN);//出租时间重叠或包含
                            }
                        }
                    }
                }
                //存json字符串
                String parse = JSONUtil.parse(param.getRentTimes()).toString();
                updateWrapper.set("rent_start_date",param.getRentStartDate())
                        .set("rent_end_date",param.getRentEndDate())
                        .set("rent_time",parse);
                stallRentTimeMapper.update(null,updateWrapper);
                stallInfoMapper.update(null,new UpdateWrapper<StallInfo>()
                        .eq("stall_info_id",param.getStallInfoId())
                        .set("stall_up_down_state",StateData.STALL_STATE_UP));
                return true;
            }
        }else if((!StringUtils.hasLength(param.getRentEndDate()) && StringUtils.hasLength(param.getRentStartDate()))
                ||(StringUtils.hasLength(param.getRentEndDate()) && !StringUtils.hasLength(param.getRentStartDate()))){
            throw new StallException(StallExceptionCode.STALL_RENT_DATE_PARAM_ERROR);//请完善出租日期段信息
        }

        List<SetRentTimeForm> setRentTimeForms = param.getRentTimes();
        if (setRentTimeForms!=null){
//-----------------------------------时间段判断---------------------------------
            for (SetRentTimeForm setRentTimeForm : setRentTimeForms) {
                if (!( 0 <= setRentTimeForm.getStartTime() && setRentTimeForm.getStartTime()<=23) ) {
                    throw new StallException(StallExceptionCode.START_TIME_0_23);//开始时间时间范围：0-23
                }
                if (!( 1 <= setRentTimeForm.getEndTime()  && setRentTimeForm.getEndTime()<=24)) {
                    throw new StallException(StallExceptionCode.END_TIME_1_24);//结束时间时间范围：1-24
                }
            }

            for (int i = 0; i < setRentTimeForms.size(); i++) {
                for (int j = 0; j < setRentTimeForms.size(); j++) {
                    if (i!=j){
                        SetRentTimeForm rentTimeForm1 = setRentTimeForms.get(i);
                        SetRentTimeForm rentTimeForm2 = setRentTimeForms.get(j);
                        if(!((rentTimeForm1.getStartTime()<rentTimeForm2.getStartTime()
                                &&rentTimeForm1.getEndTime()<=rentTimeForm2.getStartTime())
                                ||
                                (rentTimeForm1.getStartTime()>=rentTimeForm2.getEndTime()
                                        &&rentTimeForm1.getEndTime()>rentTimeForm2.getEndTime())
                        )
                        ) {
                            throw new StallException(StallExceptionCode.RENT_TIME_OVERLAP_OR_CONTAIN);//出租时间重叠或包含
                        }
                    }
                }
            }
            String s = JSONUtil.parse(setRentTimeForms).toString();
            updateWrapper.set("rent_time",s);
            updateWrapper.set("rent_start_date","");
            updateWrapper.set("rent_end_date","");
        }else {
            updateWrapper.set("rent_time","");
        }
        stallRentTimeMapper.update(null,updateWrapper);
        stallInfoMapper.update(null,new UpdateWrapper<StallInfo>()
                .eq("stall_info_id",param.getStallInfoId())
                .set("stall_up_down_state",StateData.STALL_STATE_UP));
        return true;
    }

    /**
     * rentersSetDown:出租客设置车位下架
     * @param stallInId :车位信息id
     * @return Boolean
     * @throws Exception
     */
    @Override
    @Transactional
    public Boolean rentersSetDown(Integer stallInId) throws Exception {
        StallInfo stallInfo = getById(stallInId);
        if (stallInfo==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_OBJECT_IS_NULL);//车位对象不存在
        }
        UpdateWrapper<StallInfo> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("stall_info_id",stallInId);
        if (stallInfo.getStallUpDownState()== StateData.STALL_STATE_DOWN) {
            throw new StallException(StallExceptionCode.STALL_ALREADY_IS_DOWN);//车位已下架
        }else if (stallInfo.getStallUpDownState()== StateData.STALL_STATE_UP){
            updateWrapper.set("stall_up_down_state",StateData.STALL_STATE_DOWN);
        }else {
            throw new StallException(StallExceptionCode.STALL_UP_DOWN_PARAM_ERROR);//车位上下架参数错误
        }
        stallInfoMapper.update(null,updateWrapper);
        return true;
    }

    /**
     * certifiedStallDetails:车位详情（物业根据车位信息id查询车位详情）
     * @param stallInfoId 车位信息id
     * @param certifiedAccountId :物业账号id
     * @return CertifiedStallDetailsDTO：车位信息dto参数对象
     * @throws Exception
     */
    @Override
    public CertifiedStallDetailsDTO certifiedStallDetails(Integer stallInfoId,Integer certifiedAccountId) throws Exception {
        StallInfo stallInfo = getById(stallInfoId);
        if (stallInfo==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_OBJECT_IS_NULL);//车位对象不存在
        }
        SelectRentersInfoByIdDTO selectRentersInfoByIdDTO = serveCallClass.rentersInfoCallById(stallInfo.getRentersInfoId());
        if (selectRentersInfoByIdDTO==null) {
            throw new StallException(StallExceptionCode.RENTERS_INFO_NO_EXISTS);//出租客信息对象不存在
        }
        SelectCertifiedInfoDTO selectCertifiedInfoDTO = serveCallClass.certifiedServerCall(certifiedAccountId);
        if (selectCertifiedInfoDTO==null) {
            throw new StallException(StallExceptionCode.CERTIFIED_INFO_NOT_EXISTS);//物业信息对象不存在
        }
        CertifiedStallDetailsDTO dto = BeanUtil.toBean(stallInfo, CertifiedStallDetailsDTO.class);
        dto.setCertifiedInfoName(selectCertifiedInfoDTO.getCertifiedInfoName());
        dto.setRentersInfoTel(selectRentersInfoByIdDTO.getRentersInfoTel());
        dto.setRentersInfoName(selectRentersInfoByIdDTO.getRentersInfoName());
        return dto;
    }

    /**
     * selectStallRentById 用户根据车位信息id查询StallRentDto
     * @param stallInfoId
     * @return StallRentDto
     */
    @Override
    public StallRentDto selectStallRentById(Integer stallInfoId) {
        //获取车位信息（对象，状态，归属的判断）
        StallInfo stallInfo = getById(stallInfoId);
        if (stallInfo==null) {
            throw new StallException(StallExceptionCode.STALL_INFO_OBJECT_IS_NULL);//车位对象不存在
        }
        if (stallInfo.getStallUpDownState()== StateData.STALL_STATE_DOWN) {
            throw new StallException(StallExceptionCode.STALL_ALREADY_IS_DOWN);//车位已下架
        }else if (stallInfo.getStallUpDownState()!=StateData.STALL_STATE_UP){
            throw new StallException(StallExceptionCode.STALL_STATE_PARAM_ERROR);//车位状态参数错误
        }
        if (stallInfo.getStallInfoAffiliation()== StateData.STALL_IS_CERTIFIED) {
            StallRentDto dto = new StallRentDto();
            dto.setIsPlan(StateData.STALL_IS_NOT_PLAN);
            return dto;
        }else if(stallInfo.getStallInfoAffiliation()!=StateData.STALL_IS_RENTERS){
            throw new StallException(StallExceptionCode.STALL_AFFILIATION_PARAM_ERROR);//车位归属参数错误
        }else {
            //获取出租时间（对象、出租日期段、出租时间的判断）
            StallRentTime stallRentTime = stallRentTimeMapper.selectOne(
                    new QueryWrapper<StallRentTime>()
                            .eq("stall_info_id",stallInfo.getStallInfoId()));
            if (stallRentTime==null) {
                throw new StallException(StallExceptionCode.STALL_RENT_TIME_OBJECT_IS_NULL);//车位出租对象不存在
            }
            if (!StringUtils.hasLength(stallRentTime.getRentStartDate())
                    && !StringUtils.hasLength(stallRentTime.getRentEndDate())) {
                StallRentDto dto = new StallRentDto();
                if (stallRentTime.getRentTime()==null) {
                    dto.setIsPlan(StateData.STALL_IS_NOT_PLAN);
                    return dto;
                }
                //时间段判断设置
                String rentTime = stallRentTime.getRentTime();
                JSONArray jsonArray = JSONUtil.parseArray(rentTime);
                List<JSONObject> jsonObjectList = jsonArray.toList(JSONObject.class);
                ArrayList<RentTimeForm> rentTimeForms = new ArrayList<>();

                for (JSONObject jsonObject : jsonObjectList) {
                    int startTime = jsonObject.getInt("startTime");
                    int endTime = jsonObject.getInt("endTime");
                    RentTimeForm timeRange = new RentTimeForm(startTime, endTime);
                    rentTimeForms.add(timeRange);
                }
                System.out.println(rentTimeForms);
                String src="";
                for (RentTimeForm rent : rentTimeForms) {
                    if (rent==null) {

                    }else
                    if (src.equals(""))  src = rent.getStartTime()+","+rent.getEndTime();
                    else src =src+","+rent.getStartTime()+","+rent.getEndTime();
                }
                List<Integer> indexList = StringDispose.getRepetitionIndex(src);
                String numStringSort = StringDispose.numStringSort(src);
                String numStringDeduplication = StringDispose.getNumStringDeduplication(numStringSort, indexList);
                List<String> numberList = Arrays.asList(numStringDeduplication.split(","));

                Set<TimeDto> timeDtoSet = new HashSet<>();
                for (int i = 0; i < numberList.size(); i++) {
                    TimeDto timeDto = new TimeDto();
                    if(2*i+1<numberList.size()){
                        String s1 = numberList.get(2*i);
                        String s2 = numberList.get(2*i+1);
                        timeDto.setStartTime(Integer.parseInt(s1));
                        timeDto.setEndTime(Integer.parseInt(s2));
                        timeDtoSet.add(timeDto);
                    }
                }
                dto.setIsPlan(StateData.STALL_IS_PLAN);
                dto.setPlanTimes(timeDtoSet);
                return dto;
            }else if((!stallRentTime.getRentStartDate().equals("") && stallRentTime.getRentEndDate().equals("") )
                    ||(stallRentTime.getRentStartDate().equals("") && !stallRentTime.getRentEndDate().equals("") )) {
                throw new StallException(StallExceptionCode.STALL_RENT_TIME_DB_PARAM_ERROR);//数据库车位出租时间参数错误
            }
            StallRentDto dto = new StallRentDto();
            if (stallRentTime.getRentTime()==null) {
                dto.setIsPlan(StateData.STALL_IS_NOT_PLAN);
                return dto;
            }
            dto.setIsPlan(StateData.STALL_IS_NOT_PLAN);
            dto.setEndDate(DateUtil.stringToLocalDate(stallRentTime.getRentEndDate()));
            dto.setStartDate(DateUtil.stringToLocalDate(stallRentTime.getRentStartDate()));
            String rentTime = stallRentTime.getRentTime();
            //时间段判断设置
            JSONArray jsonArray = JSONUtil.parseArray(rentTime);
            List<JSONObject> jsonObjectList = jsonArray.toList(JSONObject.class);
            ArrayList<RentTimeForm> rentTimeForms = new ArrayList<>();

            for (JSONObject jsonObject : jsonObjectList) {
                int startTime = jsonObject.getInt("startTime");
                int endTime = jsonObject.getInt("endTime");
                RentTimeForm timeRange = new RentTimeForm(startTime, endTime);
                rentTimeForms.add(timeRange);
            }
            String src="";
            for (RentTimeForm rent : rentTimeForms) {
                if (src.equals(""))  src = rent.getStartTime()+","+rent.getEndTime();
                else src =src+","+rent.getStartTime()+","+rent.getEndTime();
            }
            List<Integer> indexList = StringDispose.getRepetitionIndex(src);
            String numStringSort = StringDispose.numStringSort(src);
            String numStringDeduplication = StringDispose.getNumStringDeduplication(numStringSort, indexList);
            List<String> numberList = Arrays.asList(numStringDeduplication.split(","));

            Set<TimeDto> timeDtoSet = new HashSet<>();
            for (int i = 0; i < numberList.size(); i++) {
                TimeDto timeDto = new TimeDto();
                if (2*i+1<numberList.size()){
                    String s1 = numberList.get(2*i);
                    String s2 = numberList.get(2*i+1);
                    timeDto.setStartTime(Integer.parseInt(s1));
                    timeDto.setEndTime(Integer.parseInt(s2));
                    timeDtoSet.add(timeDto);
                }
            }
            dto.setIsPlan(StateData.STALL_IS_PLAN);
            dto.setPlanTimes(timeDtoSet);
            return dto;
        }
    }




    public static void main(String[] args) {
        String numbers = "3,12,33,24,5,6";
        List<String> numberList = Arrays.asList(numbers.split(","));
        for (int i = 0; i < numberList.size(); i++) {
            if (2*i+1<numberList.size()){
                System.out.println(numberList.get(2*i));
//                System.out.println(numberList.get(2*i+1));
                int i1 = Integer.parseInt(numberList.get(2 * i + 1));
                System.out.println(i1);
            }else  return;
            System.out.println("------------");
        }

        System.out.println(numberList);
//        List<RentTimeForm> rentTimeForms = new ArrayList<>();
//        RentTimeForm rentTimeForm1 = new RentTimeForm();
//        rentTimeForm1.setStartTime(0);
//        rentTimeForm1.setEndTime(1);
//        RentTimeForm rentTimeForm2 = new RentTimeForm();
//        rentTimeForm2.setStartTime(1);
//        rentTimeForm2.setEndTime(3);
//        RentTimeForm rentTimeForm4 =  new RentTimeForm();
//        rentTimeForm4.setStartTime(4);
//        rentTimeForm4.setEndTime(5);
//        rentTimeForms.add(rentTimeForm1);
//        rentTimeForms.add(rentTimeForm2);
//        rentTimeForms.add(rentTimeForm4);

//        String myString = String.join(",", rentTimeForms.stream().map(Object::toString).toArray(String[]::new));
//        System.out.println(myString);

//        String src="";
//        for (RentTimeForm rentTime : rentTimeForms) {
//            if (src.equals(""))  src = rentTime.getStartTime()+","+rentTime.getEndTime();
//            else src =src+","+rentTime.getStartTime()+","+rentTime.getEndTime();
//        }System.out.println(src);

//        UserSelectStallInfoParam param = new UserSelectStallInfoParam();
//        String s = "2023-11-15 11:20:20";
//        param.setStartTime(s);
//        String starDate = param.getStartTime().substring(0, 10);
//        String starTime = param.getStartTime().substring(11, 19);
//        System.out.println(starDate);
//        System.out.println(starTime);
    }

}
